package org.lanqiao.music.web.controller;

import org.lanqiao.music.common.utils.Result;
import org.lanqiao.music.common.dto.SingerDTO;
import org.lanqiao.music.system.entity.Singer;
import org.lanqiao.music.system.service.SingerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/*
歌手控制类
*/
@RestController
@RequestMapping("api/singer")
public class SingerController {
    @Autowired
    private SingerService singerService;

    //id查询歌手
    @GetMapping("/searchById")
    public Singer getById(Integer singerId){
        return singerService.queryById(singerId);
    }
    //查询歌手
    @GetMapping("/search")
    public Result getSinger(SingerDTO dto){
        Result result = Result.success(singerService.queryAllSinger(dto));
        return result;
    }

    //增加
    @PostMapping("/insert")
    public Result insert(@RequestBody Singer singer){
        int r = singerService.insert(singer);
        if (r == 1){
            return Result.success("添加成功");
        }
        return Result.fail("添加失败") ;
    }

   //批量新增
    @PostMapping("/batchInsert")
    public Result insertBatch(@RequestBody List<Singer> singerList){
        int r = singerService.insertBatch(singerList);
        return Result.success(r);
    }

    //删除
    @DeleteMapping("/{singerId}")
    public Result deleteId(@PathVariable("singerId") Integer singerId){
        int r = singerService.deleteById(singerId);
        if (r == 1){
            return Result.success("删除成功");
        }
        return Result.fail("删除失败") ;
    }


    //修改
    @PutMapping("/update")
    public Result updateSinger(@RequestBody Singer singer){
        int r = singerService.update(singer);
            if (r > 0){
                return Result.success("修改成功");
            }else {
                return Result.fail("修改失败");
            }
        }
}
